<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item label="车牌号">
        <el-select filterable style="width: 100px" v-model="dataForm.truckId" placeholder="车牌号" @change="onChange">
          <el-option label="全部" value=""></el-option>
          <el-option
            v-for="item in vehicelCodeList"
            :key="item.id"
            :label="item.licensePlate"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="车辆所属" >
        <el-select  style="width: 130px"  v-model="dataForm.belong" placeholder="车辆所属">
          <el-option label="全部" value=""></el-option>
          <el-option
            v-for="item in vehicelOwnList"
            :key="item.value"
            :label="item.label"
            :value="+item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item  label="能源类型">
        <el-select  style="width: 130px"  v-model="dataForm.energyType" placeholder="能源类型">
          <el-option
            label="全部"
            value="">
          </el-option>
          <el-option
            v-for="item in vehicelTypeList"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          :editable="false"
          type="date"
          v-model="dataForm.startDate"
          value-format="yyyy-MM-dd"
          style="width:150px;"
          placeholder="起始日期">
        </el-date-picker>
        ~
        <el-date-picker
          :editable="false"
          type="date"
          v-model="dataForm.endDate"
          style="width:150px;"
          value-format="yyyy-MM-dd"
          placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <!--        <el-button v-if="isAuth('tms:shipmentrecord:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>-->
        <!--        <el-button v-if="isAuth('tms:shipmentrecord:import')" type="primary" @click="onImport()">导入</el-button>-->
        <!--        <el-button v-if="isAuth('tms:shipmentrecord:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>-->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">

      <el-table-column
        fixed
        prop="licensePlate"
        header-align="center"
        align="center"
        label="车牌号">
      </el-table-column>


      <el-table-column
        prop="shipmentAmount"
        header-align="center"
        align="center"
        label="总运费">
      </el-table-column>
      <el-table-column
        prop="receiveWeight"
        header-align="center"
        align="center"
        label="运输吨数">
      </el-table-column>

      <el-table-column
        prop="shipmentCount"
        header-align="center"
        align="center"
        label="运输车次">
      </el-table-column>

      <el-table-column
        prop="fuelAmount"
        header-align="center"
        align="center"
        label="燃料费(油/电)">
      </el-table-column>

      <el-table-column
        prop="otherAmount"
        header-align="center"
        align="center"
        label="其他费用(元)">
      </el-table-column>
      <el-table-column
        prop="energyType"
        header-align="center"
        align="center"
        label="车辆类别">
        <template slot-scope="scope">
          {{ scope.row.energyType == 1 ? '燃油车' : '电动车' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="type"
        header-align="center"
        align="center"
        label="车辆所属">
        <template slot-scope="scope">
          {{scope.row.belong ==1?'自有车辆':'外部车辆'}}
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
import Utils from '@/utils/utils'
export default {
  data () {
    return {
      vehicelOwnList:[{label:'自有车辆',value:1},{label:'外部车辆',value:2}],
      vehicelTypeList:[],
      dataForm: {
        truckId: '',
        startDate: '',
        endDate: '',
        energyType:'',
        belong:''
      },
      dataList: [],
      vehicelCodeList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
      importVisible: false
    }
  },
  components: {},
  activated () {
    this.dataForm.startDate = Utils.getCurrentMonth() + '-01'
    this.dataForm.endDate = Utils.getCurrentDate()
    this.getDataList()
    this.getVehicelCodeList()
    this.getVehicelTypeList()
  },
  methods: {
    onChange () {
      this.pageIndex = 1
      this.getDataList()
    },
    // 获取数据列表
    getVehicelTypeList () {

      this.$http({
        url: this.$http.adornUrl('/sys/config/list'),
        method: 'get',
        params: this.$http.adornParams({
          'page': 1,
          'limit': 99,
          'paramKey': 'energyType'
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.vehicelTypeList = JSON.parse(data.page.list[0].paramValue)
        }

      })
    },
    getVehicelCodeList () {
      this.$http({
        url: this.$http.adornUrl('/tms/truck/list'),
        method: 'get',
        params: this.$http.adornParams({
          'page': 1,
          'limit': 999
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.vehicelCodeList = data.page.list

        }
      })
    },
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/statistic/truck'),
        method: 'get',
        params: this.$http.adornParams({
          'page': this.pageIndex,
          'limit': this.pageSize,
          id: this.dataForm.truckId,
          energyType:this.dataForm.energyType,
          startDate: this.dataForm.startDate,
          endDate: this.dataForm.endDate,
          belong:this.dataForm.belong
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list
          this.totalPage = data.page.totalCount
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    },
    // 多选
    selectionChangeHandle (val) {
      this.dataListSelections = val
    }
  }
}
</script>
